/**
 * @file /include/rhzd_assist/dynamic_button.hpp
 *
 * @brief Qt based gui for rhzd_assist.
 *
 * @date October 2025
 **/
#ifndef _QT_DYNAMIC_BUTTON_HPP_
#define _QT_DYNAMIC_BUTTON_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include <QPushButton>
#include <QTimer>
#include <QMouseEvent>

class DynamicButton : public QPushButton {
    Q_OBJECT

public:
    explicit DynamicButton(const QString &text, QWidget *parent = nullptr);
    virtual ~DynamicButton() = default;

    // 设置长按时间阈值（毫秒）
    void setLongPressThreshold(int milliseconds);

    // 获取当前长按时间阈值
    int getLongPressThreshold() const;
    int setCmd(const QString &cmd);
    QString getCmd() const;

protected:
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

Q_SIGNALS:
    void sigDbuttonDelete(DynamicButton *button);

private slots:
    void onLongPress();

private:
    QTimer *pressTimer;
    int longPressThreshold;
    bool isLongPressing;
    QString cmd;
    void setupButtonStyle();
    void setPressedStyle();
    void setNormalStyle();
};

#endif // _QT_DYNAMIC_BUTTON_HPP_